// @ts-ignore
/* eslint-disable */
import {request} from '@umijs/max';
import {UserChangeStatusParams, UserListItem, UserResetPasswordParams, UserSelectListData} from './data';
import {AuthoritySelectListData} from './data';
import {OrganizationListItem} from "@/pages/organization/org-list/data";

/** 获取用户列表 GET /api/user/list */
export async function fUserList(
    params: {
        // query
        /** 当前的页码 */
        current?: number;
        /** 页面的容量 */
        pageSize?: number;
    },
    options?: { [key: string]: any },
) {
    return request<{
        data: UserListItem[];
        /** 列表的内容总数 */
        total?: number;
        success?: boolean;
    }>('/api/user/list', {
        method: 'GET',
        params: {
            ...params,
        },
        ...(options || {}),
    });
}

/** 更新用户信息 PUT /api/user/edit */
export async function editUser(data: { [key: string]: any }, options?: { [key: string]: any }) {
    return request<API.ApiResponse>('/api/user/edit', {
        data,
        method: 'PUT',
        ...(options || {}),
    });
}


/** 新增用户 POST /api/user/add */
export async function addUser(data: { [key: string]: any }, options?: { [key: string]: any }) {
    return request<UserListItem>('/api/user/add', {
        data,
        method: 'POST',
        ...(options || {}),
    });
}

/** 删除用户 DELETE /api/user/delete */
export async function userDelete(data: { userIds: string[] }, options?: { [key: string]: any }) {
    return request<Record<string, any>>('/api/user/delete', {
        data,
        method: 'DELETE',
        ...(options || {}),
    });
}


/** 新增用户 POST /api/user/add */

export async function resetPassword(body: UserResetPasswordParams, options?: { [key: string]: any }) {
    return request<API.ErrorResponse>('/api/user/resetPassword', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {}),
    });
}

export async function changePassword(data: { [key: string]: any }, options?: { [key: string]: any }) {
    return request<UserListItem>('/api/user/changePassword', {
        data,
        method: 'POST',
        ...(options || {}),
    });
}

export async function syncLdap(data: { [key: string]: any }, options?: { [key: string]: any }) {
    return request<UserListItem>('/api/user/syncLdap', {
        data,
        method: 'POST',
        ...(options || {}),
    });
}

/** 角色列表 POST /api/authority/list */
export async function authorityList(
    params: {
        organizationId?: string;
    },
    options?: { [key: string]: any },
) {
    return request<{
        data: AuthoritySelectListData[];
    }>('/api/authority/list', {
        method: 'POST',
        params: {
            ...params,
        },
        ...(options || {}),
    });
}

/** 更改用户状态 POST /api/user/changeStatus */
export function changeStatus(body: UserChangeStatusParams, options?: { [key: string]: any }) {
    return request<API.ErrorResponse>('/api/user/changeStatus', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {}),
    });
}


/** 获取用户选择列表 GET /api/user/selectList */
export async function userSelectList(
    params: {
        organizationId?: string;
        username?: string;
    },
    options?: { [key: string]: any },
) {
    return request<{
        data: UserSelectListData[];
    }>('/api/user/selectList', {
        method: 'GET',
        params: {
            ...params,
        },
        ...(options || {}),
    });
}
